import { type ClassValue, clsx } from 'clsx'
import { twMerge } from 'tailwind-merge'
import { getChildrenToStartJSONSchema } from './toJSONSchema'
import { useNode } from '@vue-flow/core'
export function cn(...inputs: ClassValue[]) {
  return twMerge(clsx(inputs))
}


export function getQueryParam(param:string) {
  const urlParams = new URLSearchParams(window.location.search);
  return urlParams.get(param);
}
 
export function setNodeOutPut (prevNode:any,outputData:any){
  const node = useNode()
  return getChildrenToStartJSONSchema(outputData)
}
export function findConnectedNodes(currentNodeId,edges,nodes) {
  const visited = new Set()
  const connectedNodes = []
  function dfs(nodeId:string) {
    if (visited.has(nodeId)) return
    visited.add(nodeId)

    const node = nodes.find((n) => n.id === nodeId)
    if (node) {
      connectedNodes.push(node)
    }

    edges.forEach((edge) => {
      // if (edge.source === nodeId && !visited.has(edge.target)) {
      //   dfs(edge.target)
      // } 
      //判断是否是起点连线
      if (edge.target === nodeId && !visited.has(edge.source)) {
        dfs(edge.source)
      }
    })
  }

  dfs(currentNodeId)
  const result = connectedNodes.filter((node) => node.id !== currentNodeId)
  return result
}